<?php

namespace app\index\service;

use app\common\model\Help;
use app\index\dao\HelpDao;
use app\index\model\UM as UM;
use think\Collection;

/**
 * Class HelpService
 * @package app\my\service
 */
class HelpService
{
    // dao
    private HelpDao $helpDao;

    public function __construct(HelpDao $helpDao)
    {
        $this->helpDao = $helpDao;
    }

    /**
     * 列表
     * @param UM|null $user
     * @param int|null $page
     * @param int|null $page_size
     * @return Collection
     */
    public function index(?UM $user, $categoryId, ?int $page = null, ?int $page_size = null): Collection
    {
        if($categoryId == 1){
            $categoryId = null;
        }

        $categoryIds = [];
        if (is_id($categoryId)) {
            $categoryIds = [$categoryId];
        }

        //这里如果要修改查询，建议把查询放到dao层去
        return $this->helpDao->select($categoryIds, $page, $page_size);
    }

    /**
     * 查询
     * @param \app\index\model\UM|null $user
     * @param int $id
     * @return \app\common\model\Help
     */
    public function read(?UM $user, int $id): ?Help
    {
        //这里如果要修改查询，建议把查询放到dao层去
        return $this->helpDao->findByPK($id, true);
    }

}
